<?php
$posts = $args['posts'] ?? [];
if (empty($posts)) {
    $posts = get_random_posts($args['pagesize'] ?? 8);
}
?>
<div class="cti5">
    <section class="i5">
        <?php
        foreach ($posts as $post) {
        ?>
            <a class="grid" href="<?= $post['link'] ?>" title="<?= $post['title'] ?>">
                <img src="<?= $post['thumbnail'] ?>" alt="<?= $post['title'] ?>">
                <span><?= $post['date'] ?></span>
                <section class="grid">
                    <h3 class="nowrap2"><?= $post['title'] ?></h3>
                </section>
            </a>
        <?php
        }
        ?>
    </section>
</div>

<style>
    div.cti5 {
        container-type: inline-size;
        container-name: i5;
    }

    section.i5 {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: var(--gap);
    }

    section.i5>a {
        grid-template-columns: auto;
        position: relative;
        border: 1px solid var(--color-border);
        border-radius: var(--border-radius);
        transition: var(--transition);
        background-color: var(--color-primary);
        position: relative;
    }

    section.i5>a>img {
        width: 100%;
        height: 14rem;
    }

    section.i5>a>span {
        padding-right: 1rem;
    }

    section.i5>a>section {
        padding: var(--gap);
        backdrop-filter: blur(10px);
        background-color: rgba(255, 255, 255, 0.6);
        border: 1px solid rgba(255, 255, 255, 0.3);
        bottom: 0;
        left: 0;
        right: 0;
    }

    section.i5>a>img:hover,
    section.i5>a>section:hover {
        cursor: pointer;
    }

    @container i5 (max-width: 1200px) {
        section.i5>a>img {
            height: 8rem;
        }
    }

    @container i5 (max-width: 1024px) {
        section.i5>a {
            grid-template-columns: auto;
        }

        section.i5>a>img {
            height: 12rem;
        }

        section.i5>a:nth-child(1)>img {
            height: 12rem;
        }

        section.i5 {
            grid-template-columns: 1fr 1fr 1fr;
        }
    }

    @container i5 (max-width: 768px) {
        section.i5 {
            grid-template-columns: 1fr 1fr ;
        }

        section.i5>a:nth-child(3) {
            grid-column: auto;
        }

        section.i5>a:nth-child(4) {
            grid-column: auto;
        }

        section.i5>a>img {
            height: 16rem;
        }
    }

    @container i5 (max-width: 576px) {
        section.i5 {
            grid-template-columns: 1fr;
        }
    }
</style>